package cn.dujc.superkid.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.CourseVideoActivity;
import cn.dujc.superkid.bean.VideoListResult;

public class VideoChapterAdapter extends  RecyclerView.Adapter<VideoChapterAdapter.MyViewHolder> {
    private final String  TAG  = VideoChapterAdapter.class.getName();
    private Context mContext;
    private List<VideoListResult.VideoEntity> list;
    private String video_id;
    private String course_id;

    public VideoChapterAdapter(List<VideoListResult.VideoEntity> list, Context mContext,String video_id,String course_id) {
        this.list = list;
        this.mContext = mContext;
        this.video_id =video_id;
        this.course_id = course_id;
        Log.i(TAG,"==============caizhijia====video_id=====" +video_id);
    }


    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_chapter, parent, false);
        return new MyViewHolder(view);
    }


    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.lessonname.setText((position+1)+"、"+ list.get(position).getVideo_title());
        if (list.get(position).getId().equals(video_id)){

            holder.lessonname.setTextColor(Color.rgb(0, 0, 0));
        }
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in = new Intent();
                in.setClass(mContext, CourseVideoActivity.class);
                in.putExtra("video_id", list.get(position).getId());
                in.putExtra("course_id", course_id);
                in.putExtra("is_learn", "2");
                in.putExtra("videoTitle",list.get(position).getVideo_title());
                mContext.startActivity(in);
                ((Activity)mContext).finish();

            }
        });

//        Log.i(TAG,"==============caizhijia======list.size()=====" +list.get(position).getClass_title());

//            Bitmap bitmap = getImageBitmap(list.get(position).getCover());
//            holder.item_iv_couse_image.setImageBitmap(bitmap);
//
    }


    public int getItemCount() {

        return list.size();
    }



    class MyViewHolder extends RecyclerView.ViewHolder {
        private View mView;
        private TextView lessonname;


        public MyViewHolder(View itemView) {
            super(itemView);
            mView = itemView;

            lessonname = itemView.findViewById(R.id.lessonname);

//            resolvtion = itemView.findViewById(R.id.error_resolvtion);
//            continu = itemView.findViewById(R.id.error_continu);

        }
    }
}